﻿using System.Net;
using System.Threading;
using Fadd.IO.Consoles;
using Fadd.Messaging;
using Fadd.Net;
using Xunit;

namespace Fadd.Test.Console
{
    /*
    public class RemoteConsoleTest : IMessageBroker
    {
        private RemoteConsole _console;
        private IMessage _receivedMessage;
        private RemoteConsole _remoteEnd;
        private BinaryChannel _remoteChannel;

        public RemoteConsoleTest()
        {
            CreateEndPoints(new IPEndPoint(IPAddress.Loopback, 9933));
        }


        private void CreateEndPoints(IPEndPoint endPoint)
        {
            var server = new SimpleServer(endPoint, s =>
                                                        {
                                                            _remoteChannel = new BinaryChannel(s);
                                                            _remoteEnd = new RemoteConsole(this, _remoteChannel);
                                                            _remoteChannel.Start();
                                                        });
            server.Start(5);
            _console = new RemoteConsole(this, endPoint);
            _console.Start();
        }

        [Fact]
        public void ConsoleOutput()
        {
            _console.WriteLine("Hello world");
            Thread.Sleep(500);

            Assert.NotNull(_receivedMessage);
            Assert.Equal("Hello world", ((ConsoleOutput) _receivedMessage).Text);
        }

        [Fact]
        public void Command()
        {
            var cmd = new Command("list", "everything");
            _remoteChannel.Send(cmd);
            Thread.Sleep(500);

            Assert.NotNull(_receivedMessage);
            var receivedCmd = _receivedMessage as Command;
            Assert.NotNull(receivedCmd);
            Assert.Equal(cmd.Name, receivedCmd.Name);
            Assert.Equal(cmd.Arguments.Length, receivedCmd.Arguments.Length);
            Assert.Equal(cmd.Arguments[0], receivedCmd.Arguments[0]);
        }

        [Fact]
        public void TestDisconnect()
        {
            
        }

        #region IMessageBroker Members

        public void Publish(IMessage message)
        {
            _receivedMessage = message;
        }

        #endregion
    }
     * */
}